package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: Tangguo
 * @Date: 2023-06-08  16:24
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;


    /**
     *  查询所有频道
     * @param :
     * @return ResponseResult
     */
    @GetMapping("/channels")
    public ResponseResult findAll(){
        return wmChannelService.findAll();
    }


    /**
     * 频道名称模糊分页查询
     * @param dto:
     * @return ResponseResult
     */
    @PostMapping("/list")
    public ResponseResult findByNameWithPage(@RequestBody ChannelDto dto){
        return wmChannelService.findByNameWithPage(dto);

    }

    /**
     * 新增频道
     * @param wmChannel:
     * @return ResponseResult
     */
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody WmChannel wmChannel){
        return wmChannelService.insert(wmChannel);

    }

    /**
     * 修改频道
     * @param wmChannel:
     * @return ResponseResult
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        return wmChannelService.update(wmChannel);

    }


    /**
     * 删除频道
     * @param id:
     * @return ResponseResult
     */
    @GetMapping ("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        return wmChannelService.delete(id);

    }

}
